package weekMatch.two_101;

import java.util.Arrays;

public class LeeCode_01 {
    public static void main(String[] args) {
        System.out.println(minNumber(new int[]{4, 1, 3}, new int[]{5, 7}));
        System.out.println(minNumber(new int[]{3,5,2,6}, new int[]{3,1,7}));
    }
    private static int minNumber(int[] nums1, int[] nums2) {
        Arrays.sort(nums1);
        Arrays.sort(nums2);
        int res = Integer.MAX_VALUE;
        for (int i = 0; i < nums1.length; i++) {
            for (int j = 0; j < nums2.length; j++) {
                int num1 = nums1[i];
                int num2 = nums2[j];
                if (num1 == num2)
                    res = Math.min(res, num1);
                res = Math.min(res, num1 < num2 ? num1 * 10 + num2 : num2 * 10 + num1);
            }
        }
        return res;
    }
}
